﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Xml;
using System.Web;
using System.Text;
using Jumbot.Common;
using Jumbot.DataOper;
namespace JumbotCms.Extends.Translate
{
    public partial class _getxml : JumbotCms.API.FrontHtml
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;
        private string _restr = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            this._operType = q("oper");
            switch (this._operType)
            {
                default:
                    GetData();
                    break;
            }
            Response.Write(this._response);
        }
        private void GetData()
        {
            Response.Charset = "utf-8";
            Response.ContentType = "text/xml";
            Response.Cache.SetExpires(DateTime.Now);
            StringBuilder sb = new StringBuilder();
            if (Cookie.GetValue(site.CookiePrev + "user") != null)
            {
                int PSize = 5;
                int page = Str2Int(q("p"), 1);
                int countNum = 0;
                string keywords = q("q");
                string sqlStr = "";
                string whereStr = "content1 Like '%" + keywords + "%' AND [State]=1";
                if (q("type") == "2")
                    whereStr = "content2 Like '%" + keywords + "%' AND [State]=1";
                doh.Reset();
                doh.SqlCmd = "SELECT count(id) as cc FROM [jcms_extends_translate] WHERE " + whereStr;
                countNum = Convert.ToInt32(doh.GetDataTable().Rows[0]["cc"].ToString());
                sqlStr = Jumbot.Common.staticFunction.GetSql("id,content1,content2", "jcms_extends_translate", "id", PSize, page, "desc", whereStr);
                doh.Reset();
                doh.SqlCmd = sqlStr;
                DataTable dt = doh.GetDataTable();
                if (dt.Rows.Count > 0)
                {
                    sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                    sb.Append("<dict>");
                    sb.Append("<logined>1</logined>");
                    sb.Append("<def> </def>");
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        sb.Append("<sent>");
                        sb.Append("<orig><![CDATA[" + dt.Rows[i]["content1"].ToString() + "]]></orig>");
                        sb.Append("<trans><![CDATA[" + dt.Rows[i]["content2"].ToString() + "]]></trans>");
                        sb.Append("</sent>");
                    }
                    sb.Append("<pagebar><![CDATA[" + Jumbot.Common.HtmlPager.GetPageBar(2, "js", 2, countNum, PSize, page, "javascript:sendRequest(<#page#>);") + "]]></pagebar>");
                    sb.Append("</dict>");
                }
                else
                {
                    sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                    sb.Append("<dict>");
                    sb.Append("<logined>1</logined>");
                    sb.Append("<def>没有找到</def>");
                    sb.Append("</dict>");
                }
                dt.Clear();
                dt.Dispose();
            }
            else
            {
                sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                sb.Append("<dict>");
                sb.Append("<logined>-1</logined>");
                sb.Append("<def>Not Logined</def>");
                sb.Append("</dict>");
            }
            this._response = sb.ToString();
        }
    }
}
